const buf = Buffer.from('Hey!')

console.log("buf ==> ", buf);
console.log("bufStr ==> ", buf.toString());
// console.log(buf[0]);
// console.log(buf[1]);
// console.log(buf[2]);
// console.log(buf[3]);
// console.log(buf[4]);
console.log("buflength ==> ", buf.length);
for (const item of buf) {
  console.log(item);
}


// const buf2 = Buffer.alloc(1024)
// console.log("buf2 ==> ", buf2)
// console.log("buf2 ==> ", buf2.toString())
// console.log("buf2[0] ==> ", buf2[0])

const buf3 = Buffer.alloc(4)
buf3.write("hang")
console.log("buf3 ==> ", buf3.toString());
buf3[1] = 111
console.log("buf3 ==> ", buf3.toString());

// 复制
let copyBuf = Buffer.alloc(2)
// buf3.copy(copyBuf)
buf3.copy(copyBuf, 0, 0, 2)
console.log("copyBuf ==> ", copyBuf.toString());


const buf4 = Buffer.from('Hey!')
buf4.slice(0).toString() //Hey!
const slice = buf4.slice(0, 2)
console.log(slice.toString()) //He
buf4[1] = 111 //o
console.log(slice.toString()) //Ho